<?php
/**
 * @author Pham Van Diep
 * @copyright 2014
 * @description: save national
 */
// not login
// not perm add
if(!isset($AppUI->id) ||
    !isset($_SESSION['club'])||
    !isset($_SESSION['national'])||
    ($_SESSION['national']&1)<< 2== 0 ||
    !isset($_POST['nationalid'])    
) {
    redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);
}
// data input
//var_dump($_POST); die();
$intNationalId = intval($_POST['nationalid']);
$strCode       = $this->input->post('code');
if(strlen($strCode) != 2) {
    array_push($arrErr,$arrLocale['code_length']);
}
$strName = $this->input->post('name',null);
if(empty($strName) ) {
     array_push($arrErr,$arrLocale['name_required']);
}
if( !isset($arrErr) || count($arrErr)==0) {//allow save         
    //$intError = $this->national->update($AppUI->id,$intId,$intClubId,$strName, $strLogo, $strShort,$strDes, $strTag);
    $intError = 0;
    if($intError == -1) { 
        array_push($arrErr,$arrLocale['sys_update_err']);        
    }else{
        if(isset($_SESSION['NATIONAL_ERROR'])) unset($_SESSION['NATIONAL_ERROR']);
    }           
}
// occur error

if (count($arrErr) !== 0) {     
    $_SESSION['NATIONAL_ERROR'] = $arrErr;    
    redirect(HOST_BACKEND . 'national/edit?nationalid='.$intNationalId);
}
redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);
